package com.serbulent.examples.rest.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.serbulent.examples.rest.model.util.json.CustomDateSerializer;
import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias( "book" )
@Entity
public class Book implements Serializable
{
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	int id;

	@Version
	@Column(name = "version")
	private Integer version;
	
	@NotNull
	@OneToOne
	Author author;
	
	@NotNull
	String title;
	
	@NotNull
	String summary;
	
	@NotNull
	Date publishDate;
	
	public Book(){
	}
	
	public Book(int id, Author author, String title, String summary,
			Date publishDate) {
		this.id = id;
		this.author = author;
		this.title = title;
		this.summary = summary;
		this.publishDate = publishDate;
	}
	
	
	public Integer getVersion() {
		return version;
	}

	public Author getAuthor() {
		return author;
	}
	public void setAuthor(Author author) {
		this.author = author;
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	
	@JsonSerialize(using = CustomDateSerializer.class)
	public Date getPublishDate() {
		return publishDate;
	}
	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

}
